<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/user.jsp"%>
<%@ include file="/common/operatehistory.jsp"%>
<%
	User me = userByUid(token.getUid());
	Integer deptId = me.getDeptId();
	if (deptId == null) {
		Tools.encryptPrint(out, new Message(30041, "没有这个团队的信息"));
		return;
	}
	List<Map> list = QBuilder.db("basedb").select("new map(id as id, name as name, avatar  as avatar, case when title is null then '' else title end as title, jsonString as json, gender as gender, type as type, phone as phone, employeeId as employee_id)").from("User").where(new Where("hospital=", hospital).and("deptId=", deptId).and("status=", STATUS_ENABLE).and("type=", USER_EMPLOYEE)).query().getResultObj();
	String role = Tools.getDesc(me.getJson("role"), "1");
	List<String> authorizedList = null;
	if ("2".equals(role)) {
		authorizedList = QBuilder.db("basedb").select("uid").from("OperateHistory").where(new Where("hospital=", hospital).and("oid=", me.getId()).and("status=", STATUS_ENABLE).and("category=", SECTION_SECRETARY).and("operate=", ATTENTION)).query().getResultObj();
	} else {
		authorizedList = QBuilder.db("basedb").select("oid").from("OperateHistory").where(new Where("hospital=", hospital).and("uid=", me.getId()).and("status=", STATUS_ENABLE).and("category=", SECTION_SECRETARY).and("operate=", ATTENTION)).query().getResultObj();
	}
	for (Map expert:list) {
			Map jsonMap = JSONUtil.fromJson(expert.remove("json") + "", new TypeReference<Map>(){});
		User user = User.fromMap(expert, User.class);
		expert.put("avatar", getDefaultAvatar(user));
	
		expert.put("specialty", Tools.getDesc(jsonMap.get("specialty"), "暂无擅长信息"));
		expert.put("introduce", Tools.getDesc(jsonMap.get("introduce"), "暂无介绍信息"));
		expert.put("role", Tools.getDesc(jsonMap.get("role"), "1"));
		expert.put("position", Tools.getDesc(jsonMap.get("position"), ""));
		expert.put("teach_title", Tools.getDesc(jsonMap.get("teach_title"), ""));
		expert.put("phone", Tools.getDesc(user.getPhone(), "暂无手机号"));
		expert.put("authorized", 0);
		if (authorizedList.contains(user.getId() + ""))
			expert.put("authorized", 1);
	}
	if (isEmpty(list))
		msg.setErrcodeAndErrmsg(30041, "没有团队成员信息");
	msg.put("data", list);
	Tools.encryptPrint(out, msg);
%>
